package com.stefanie.eventlistenerdemo.service;

import com.stefanie.eventlistenerdemo.common.event.EventMulticaster;
import com.stefanie.eventlistenerdemo.domain.dto.UserDto;
import com.stefanie.eventlistenerdemo.domain.event.UserEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author: stefanie-zy
 * @time: 2024/1/12-15:10
 * @description: 接口实现层-用户
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {

    private final EventMulticaster eventMulticaster;

    @Override
    public void save(UserDto userDto) {
        log.info("Create a new user named {} with email {} and tel {}", userDto.getUserName(), userDto.getEmail(), userDto.getTel());
        // 触发用户事件
        UserEvent userEvent = new UserEvent(this, userDto);
        eventMulticaster.multicastEvent(userEvent);
    }
}
